const pageHelper = require('@/utils/helper/page_helper.js');
const cloudHelper = require('@/utils/helper/cloud_helper.js');



module.exports = {
    data() {
        return {
            oprt: 'admin',
            isLoad: true,
            title: ''
        };
    },
    methods: {
        /**
         * 生命周期函数--监听页面初次渲染完成
         */
        onReady: function () {},
        /**
         * 生命周期函数--监听页面显示
         */
        onShow: function () {},
        /**
         * 生命周期函数--监听页面隐藏
         */
        onHide: function () {},
        /**
         * 生命周期函数--监听页面卸载
         */
        onUnload: function () {},
        bindScanTap: function (e) {
            let meetId = this.meetId;
            let that = this;
            uni.scanCode({
                async success(res) {
                    if (!res || !res.result || !res.result.includes('meet=') || res.result.length != 20) {
                        pageHelper.showModal('错误的预约码，请重新扫码');
                        return;
                    }
                    let code = res.result.replace('meet=', '');
                    let params = {
                        meetId,
                        code
                    };
                    let options = {
                        title: '预约码核销中'
                    };
                    await cloudHelper
                        .callCloudSumbit(that.oprt + '/join_scan', params, options)
                        .then((res) => {
                            pageHelper.showModal('核销成功');
                        })
                        .catch((err) => {
                            console.log(err);
                        });
                },
                fail(err) {
                    if (err && err.errMsg == 'scanCode:fail') {
                        pageHelper.showModal('预约码核销错误，请重新扫码');
                    }
                }
            });
        }
    }
};
